package org.itzheng.myrxframe.realize.adpter.rcv;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.itzheng.and.baseutils.common.ArrayUtils;
import org.itzheng.and.baseutils.common.StrUtils;
import org.itzheng.and.baseutils.ui.UIUtils;
import org.itzheng.and.recyclerview.adapter.BaseRecyclerAdapter;
import org.itzheng.myrxframe.R;
import org.itzheng.myrxframe.realize.bean.MyMenuItem;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Title:<br>
 * Description: <br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2017/8/21.
 */
public class MainMenuAdapter extends BaseRecyclerAdapter<MainMenuAdapter.ViewHolder> {
    private List<MyMenuItem> mItems;

    public MainMenuAdapter(List<MyMenuItem> menuItems) {
        mItems = menuItems;
    }

    @Override
    public int getItemCount() {
        return ArrayUtils.size(mItems);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            default:
                return new ViewHolder(onCreateView(parent, viewType));
        }
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        MyMenuItem item = mItems.get(position);
        holder.ivIcon.setImageResource(item.iconRes);
        holder.tvTitle.setText(StrUtils.toString(item.name));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UIUtils.startActivity(item.clazz);
            }
        });
//        holder.itemView.setOnClickListener(item.onClickListener);

    }

    @Override
    public View onCreateView(ViewGroup parent, int viewType) {
        return UIUtils.inflateAdapterView(R.layout.adapter_item_main_menu, parent);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.ivIcon)
        ImageView ivIcon;
        @BindView(R.id.tvTitle)
        TextView tvTitle;

        public ViewHolder(View itemView) {
            super(itemView);
            bindButterKnife();
        }

        private void bindButterKnife() {
            ButterKnife.bind(this, itemView);
        }
    }
}
